package org.middleware.controller;

import org.middleware.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;


//    @Autowired
//    private Environment environment;
//    @PostConstruct
//    public void checkActiveProfiles() {
//        System.out.println("====== 当前激活的Profile ======");
//        String[] activeProfiles = environment.getActiveProfiles();
//        if (activeProfiles.length == 0) {
//            System.out.println("没有激活的Profile!");
//        } else {
//            for (String profile : activeProfiles) {
//                System.out.println("激活的Profile: " + profile);
//            }
//        }
//        System.out.println("=============================");
//    }

    @PostMapping("/set")
    public String set(@RequestParam String key, @RequestParam String value) {
        redisService.set(key, value);
        return "OK";
    }

    @GetMapping("/get")
    public Object get(@RequestParam String key) {
        return redisService.get(key);
    }

    @DeleteMapping("/delete")
    public Boolean delete(@RequestParam String key) {
        return redisService.delete(key);
    }
}